package com.zifan.sever.controller;


import com.zifan.sever.bean.Salary;
import com.zifan.sever.service.ISalaryService;
import com.zifan.sever.utils.RespBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zifan
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "获取所有工资套账信息")
    @GetMapping("/")
    public List<Salary> getSalaries(){
        return salaryService.list();
    }

    @ApiOperation(value = "新增工资套账信息")
    @PostMapping("/")
    public RespBean addSalaries(@RequestBody Salary salary){
        if (salaryService.save(salary)){
            return RespBean.success("保存成功");
        }
        return RespBean.error("保存失败");
    }

    @ApiOperation(value = "更新工资套账信息")
    @PutMapping("/")
    public RespBean updateSalary(@RequestBody Salary salary){
        if (salaryService.updateById(salary)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败");
    }

    @ApiOperation("删除工资套账")
    @DeleteMapping("/{id}")
    public RespBean deleteSalary(@PathVariable("id") Integer id){
        if (salaryService.removeById(id)){
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败");
    }

}
